--------------------------------------------------------
--  File created - Tuesday-June-21-2011   
--------------------------------------------------------
  DROP TABLE "HR"."ARHIVA" cascade constraints;
  DROP TABLE "HR"."CHITANTA" cascade constraints;
  DROP TABLE "HR"."DETALII_CHITANTA" cascade constraints;
  DROP TABLE "HR"."DETALII_RETETA" cascade constraints;
  DROP TABLE "HR"."MEDICAMENT" cascade constraints;
  DROP TABLE "HR"."PRODUCATORI" cascade constraints;
  DROP TABLE "HR"."RETETA" cascade constraints;
  DROP TABLE "HR"."STOCURI" cascade constraints;
  DROP TABLE "HR"."SUBSTANTA_ACTIVA" cascade constraints;
  DROP TABLE "HR"."USERS" cascade constraints;
  DROP TABLE "HR"."VANZARI" cascade constraints;
  DROP SEQUENCE "HR"."ARHIVA_SEQUENCE";
  DROP SEQUENCE "HR"."CHITANTA_SEQUENCE";
  DROP SEQUENCE "HR"."DETALII_CHITANTA_SEQUENCE";
  DROP SEQUENCE "HR"."DETALII_RETETA_SEQUENCE";
  DROP SEQUENCE "HR"."MEDICAMENT_SEQUENCE";
  DROP SEQUENCE "HR"."PRODUCATORI_SEQUENCE";
  DROP SEQUENCE "HR"."RETETA_SEQUENCE";
  DROP SEQUENCE "HR"."STOCURI_SEQUENCE";
  DROP SEQUENCE "HR"."SUBSTANTA_ACTIVA_SEQUENCE";
  DROP SEQUENCE "HR"."USERS_SEQUENCE";
  DROP SEQUENCE "HR"."VANZARI_SEQUENCE";
--------------------------------------------------------
--  DDL for Sequence ARHIVA_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."ARHIVA_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence CHITANTA_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."CHITANTA_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence DETALII_CHITANTA_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."DETALII_CHITANTA_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence DETALII_RETETA_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."DETALII_RETETA_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence MEDICAMENT_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."MEDICAMENT_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence PRODUCATORI_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."PRODUCATORI_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence RETETA_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."RETETA_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence STOCURI_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."STOCURI_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence SUBSTANTA_ACTIVA_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."SUBSTANTA_ACTIVA_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence USERS_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."USERS_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence VANZARI_SEQUENCE
--------------------------------------------------------

   CREATE SEQUENCE  "HR"."VANZARI_SEQUENCE"  MINVALUE 1 MAXVALUE 9999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Table ARHIVA
--------------------------------------------------------

  CREATE TABLE "HR"."ARHIVA" 
   (	"ID_MEDICAMENT" NUMBER(*,0), 
	"DATA" DATE, 
	"CANTITATE" NUMBER(*,0), 
	"ID_ARHIVA" NUMBER(*,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table CHITANTA
--------------------------------------------------------

  CREATE TABLE "HR"."CHITANTA" 
   (	"ID_CHITANTA" NUMBER(*,0), 
	"DATA" DATE, 
	"ID_RETETA" NUMBER(*,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table DETALII_CHITANTA
--------------------------------------------------------

  CREATE TABLE "HR"."DETALII_CHITANTA" 
   (	"ID_CHITANTA" NUMBER(*,0), 
	"ID_VANZARE" NUMBER(*,0), 
	"ID_DETALIICHITANTA" NUMBER(*,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table DETALII_RETETA
--------------------------------------------------------

  CREATE TABLE "HR"."DETALII_RETETA" 
   (	"ID_RETETA" NUMBER(*,0), 
	"ID_SUSTANTA" NUMBER(*,0), 
	"ID_DETALIIRETETA" NUMBER(*,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table MEDICAMENT
--------------------------------------------------------

  CREATE TABLE "HR"."MEDICAMENT" 
   (	"ID_MEDICAMENT" NUMBER(*,0), 
	"ID_SUBSTANTA_ACTIVA" NUMBER(*,0), 
	"MEDICAMENT" VARCHAR2(20 BYTE), 
	"ID_PRODUCATOR" NUMBER(*,0), 
	"COST" NUMBER(*,2)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table PRODUCATORI
--------------------------------------------------------

  CREATE TABLE "HR"."PRODUCATORI" 
   (	"ID_PRODUCATOR" NUMBER(*,0), 
	"PRODUCATOR" VARCHAR2(100 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table RETETA
--------------------------------------------------------

  CREATE TABLE "HR"."RETETA" 
   (	"ID_RETETA" NUMBER(*,0), 
	"TIP_COMPENSAT" NUMBER(*,0), 
	"UNITATEA_SANITARA" VARCHAR2(100 BYTE), 
	"ASIGURAT" VARCHAR2(100 BYTE), 
	"DIAGNOSTIC" VARCHAR2(100 BYTE), 
	"DATA_PRESCRIERII" DATE, 
	"PARAFA" VARCHAR2(100 BYTE), 
	"PRESCRIPTIE" VARCHAR2(200 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table STOCURI
--------------------------------------------------------

  CREATE TABLE "HR"."STOCURI" 
   (	"ID_MEDICAMENT" NUMBER(*,0), 
	"UM" VARCHAR2(20 BYTE), 
	"CANTITATE_ACTUALA" NUMBER(*,0), 
	"ID_STOCURI" NUMBER(*,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table SUBSTANTA_ACTIVA
--------------------------------------------------------

  CREATE TABLE "HR"."SUBSTANTA_ACTIVA" 
   (	"ID_SUBSTANTA_ACTIVA" NUMBER(*,0), 
	"SUBSTANTA_ACTIVA" VARCHAR2(20 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table USERS
--------------------------------------------------------

  CREATE TABLE "HR"."USERS" 
   (	"ID_USER" NUMBER(*,0), 
	"UTILIZATOR" VARCHAR2(20 BYTE), 
	"PAROLA" VARCHAR2(100 BYTE), 
	"ISADMIN" NUMBER(1,0) DEFAULT 0
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Table VANZARI
--------------------------------------------------------

  CREATE TABLE "HR"."VANZARI" 
   (	"ID_MEDICAMENT" NUMBER(*,0), 
	"CANTITATE" NUMBER(*,2), 
	"PRET" NUMBER(*,2), 
	"ID_VANZARE" NUMBER(*,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index ARHIVA_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."ARHIVA_UK1" ON "HR"."ARHIVA" ("ID_MEDICAMENT", "DATA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index CHITANTA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."CHITANTA_PK" ON "HR"."CHITANTA" ("ID_CHITANTA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index ID_MEDICAMENT_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."ID_MEDICAMENT_PK" ON "HR"."MEDICAMENT" ("ID_MEDICAMENT") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index RETETA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."RETETA_PK" ON "HR"."RETETA" ("ID_RETETA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index DETALII_RETETA_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."DETALII_RETETA_UK1" ON "HR"."DETALII_RETETA" ("ID_RETETA", "ID_SUSTANTA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index PRODUCATORI_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."PRODUCATORI_PK" ON "HR"."PRODUCATORI" ("ID_PRODUCATOR") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index USERS_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."USERS_PK" ON "HR"."USERS" ("ID_USER") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index DETALII_RETETA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."DETALII_RETETA_PK" ON "HR"."DETALII_RETETA" ("ID_DETALIIRETETA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index DETALII_CHITANTA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."DETALII_CHITANTA_PK" ON "HR"."DETALII_CHITANTA" ("ID_DETALIICHITANTA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index DETALII_CHITANTA_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."DETALII_CHITANTA_UK1" ON "HR"."DETALII_CHITANTA" ("ID_CHITANTA", "ID_VANZARE") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index STOCURI_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."STOCURI_PK" ON "HR"."STOCURI" ("ID_STOCURI") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index VANZARI_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."VANZARI_PK" ON "HR"."VANZARI" ("ID_VANZARE") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index ARHIVA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."ARHIVA_PK" ON "HR"."ARHIVA" ("ID_ARHIVA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  DDL for Index SUBSTANTA_ACTIVA_PK
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."SUBSTANTA_ACTIVA_PK" ON "HR"."SUBSTANTA_ACTIVA" ("ID_SUBSTANTA_ACTIVA") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "SYSTEM" ;
--------------------------------------------------------
--  DDL for Index STOCURI_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "HR"."STOCURI_UK1" ON "HR"."STOCURI" ("ID_MEDICAMENT") 
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
--------------------------------------------------------
--  Constraints for Table ARHIVA
--------------------------------------------------------

  ALTER TABLE "HR"."ARHIVA" ADD CONSTRAINT "ARHIVA_PK" PRIMARY KEY ("ID_ARHIVA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."ARHIVA" ADD CONSTRAINT "ARHIVA_UK1" UNIQUE ("ID_MEDICAMENT", "DATA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."ARHIVA" MODIFY ("ID_ARHIVA" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table SUBSTANTA_ACTIVA
--------------------------------------------------------

  ALTER TABLE "HR"."SUBSTANTA_ACTIVA" ADD CONSTRAINT "SUBSTANTA_ACTIVA_PK" PRIMARY KEY ("ID_SUBSTANTA_ACTIVA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "SYSTEM"  ENABLE;
 
  ALTER TABLE "HR"."SUBSTANTA_ACTIVA" MODIFY ("ID_SUBSTANTA_ACTIVA" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table RETETA
--------------------------------------------------------

  ALTER TABLE "HR"."RETETA" ADD CONSTRAINT "RETETA_PK" PRIMARY KEY ("ID_RETETA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."RETETA" MODIFY ("ID_RETETA" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table DETALII_CHITANTA
--------------------------------------------------------

  ALTER TABLE "HR"."DETALII_CHITANTA" ADD CONSTRAINT "DETALII_CHITANTA_PK" PRIMARY KEY ("ID_DETALIICHITANTA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."DETALII_CHITANTA" ADD CONSTRAINT "DETALII_CHITANTA_UK1" UNIQUE ("ID_CHITANTA", "ID_VANZARE")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."DETALII_CHITANTA" MODIFY ("ID_CHITANTA" NOT NULL ENABLE);
 
  ALTER TABLE "HR"."DETALII_CHITANTA" MODIFY ("ID_DETALIICHITANTA" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table DETALII_RETETA
--------------------------------------------------------

  ALTER TABLE "HR"."DETALII_RETETA" ADD CONSTRAINT "DETALII_RETETA_PK" PRIMARY KEY ("ID_DETALIIRETETA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."DETALII_RETETA" ADD CONSTRAINT "DETALII_RETETA_UK1" UNIQUE ("ID_RETETA", "ID_SUSTANTA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."DETALII_RETETA" MODIFY ("ID_RETETA" NOT NULL ENABLE);
 
  ALTER TABLE "HR"."DETALII_RETETA" MODIFY ("ID_DETALIIRETETA" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table USERS
--------------------------------------------------------

  ALTER TABLE "HR"."USERS" MODIFY ("ID_USER" NOT NULL ENABLE);
 
  ALTER TABLE "HR"."USERS" ADD CONSTRAINT "USERS_PK" PRIMARY KEY ("ID_USER")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table VANZARI
--------------------------------------------------------

  ALTER TABLE "HR"."VANZARI" MODIFY ("ID_MEDICAMENT" NOT NULL ENABLE);
 
  ALTER TABLE "HR"."VANZARI" MODIFY ("ID_VANZARE" NOT NULL ENABLE);
 
  ALTER TABLE "HR"."VANZARI" ADD CONSTRAINT "VANZARI_PK" PRIMARY KEY ("ID_VANZARE")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
--------------------------------------------------------
--  Constraints for Table STOCURI
--------------------------------------------------------

  ALTER TABLE "HR"."STOCURI" ADD CONSTRAINT "STOCURI_PK" PRIMARY KEY ("ID_STOCURI")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."STOCURI" ADD CONSTRAINT "STOCURI_UK1" UNIQUE ("ID_MEDICAMENT")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."STOCURI" MODIFY ("ID_MEDICAMENT" NOT NULL ENABLE);
 
  ALTER TABLE "HR"."STOCURI" MODIFY ("UM" NOT NULL ENABLE);
 
  ALTER TABLE "HR"."STOCURI" MODIFY ("ID_STOCURI" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table CHITANTA
--------------------------------------------------------

  ALTER TABLE "HR"."CHITANTA" ADD CONSTRAINT "CHITANTA_PK" PRIMARY KEY ("ID_CHITANTA")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."CHITANTA" MODIFY ("ID_CHITANTA" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table PRODUCATORI
--------------------------------------------------------

  ALTER TABLE "HR"."PRODUCATORI" ADD CONSTRAINT "PRODUCATORI_PK" PRIMARY KEY ("ID_PRODUCATOR")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."PRODUCATORI" MODIFY ("ID_PRODUCATOR" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table MEDICAMENT
--------------------------------------------------------

  ALTER TABLE "HR"."MEDICAMENT" ADD CONSTRAINT "ID_MEDICAMENT_PK" PRIMARY KEY ("ID_MEDICAMENT")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"  ENABLE;
 
  ALTER TABLE "HR"."MEDICAMENT" MODIFY ("ID_MEDICAMENT" NOT NULL ENABLE);
--------------------------------------------------------
--  Ref Constraints for Table ARHIVA
--------------------------------------------------------

  ALTER TABLE "HR"."ARHIVA" ADD CONSTRAINT "ARHIVA_MEDICAMENT_FK1" FOREIGN KEY ("ID_MEDICAMENT")
	  REFERENCES "HR"."MEDICAMENT" ("ID_MEDICAMENT") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table DETALII_CHITANTA
--------------------------------------------------------

  ALTER TABLE "HR"."DETALII_CHITANTA" ADD CONSTRAINT "DETALII_CHITANTA_CHITANTA_FK1" FOREIGN KEY ("ID_CHITANTA")
	  REFERENCES "HR"."CHITANTA" ("ID_CHITANTA") ENABLE;
 
  ALTER TABLE "HR"."DETALII_CHITANTA" ADD CONSTRAINT "DETALII_CHITANTA_VANZARI_FK1" FOREIGN KEY ("ID_VANZARE")
	  REFERENCES "HR"."VANZARI" ("ID_VANZARE") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table DETALII_RETETA
--------------------------------------------------------

  ALTER TABLE "HR"."DETALII_RETETA" ADD CONSTRAINT "DETALII_RETETA_RETETA_FK2" FOREIGN KEY ("ID_RETETA")
	  REFERENCES "HR"."RETETA" ("ID_RETETA") ENABLE;
 
  ALTER TABLE "HR"."DETALII_RETETA" ADD CONSTRAINT "DETALII_RETETA_SUBSTANTA__FK1" FOREIGN KEY ("ID_SUSTANTA")
	  REFERENCES "HR"."SUBSTANTA_ACTIVA" ("ID_SUBSTANTA_ACTIVA") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table MEDICAMENT
--------------------------------------------------------

  ALTER TABLE "HR"."MEDICAMENT" ADD CONSTRAINT "MEDICAMENT_PRODUCATORI_FK1" FOREIGN KEY ("ID_PRODUCATOR")
	  REFERENCES "HR"."PRODUCATORI" ("ID_PRODUCATOR") ENABLE;
 
  ALTER TABLE "HR"."MEDICAMENT" ADD CONSTRAINT "MEDICAMENT_SUBSTANTA_ACTI_FK1" FOREIGN KEY ("ID_SUBSTANTA_ACTIVA")
	  REFERENCES "HR"."SUBSTANTA_ACTIVA" ("ID_SUBSTANTA_ACTIVA") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table STOCURI
--------------------------------------------------------

  ALTER TABLE "HR"."STOCURI" ADD CONSTRAINT "STOCURI_MEDICAMENT_FK1" FOREIGN KEY ("ID_MEDICAMENT")
	  REFERENCES "HR"."MEDICAMENT" ("ID_MEDICAMENT") ENABLE;
--------------------------------------------------------
--  Ref Constraints for Table VANZARI
--------------------------------------------------------

  ALTER TABLE "HR"."VANZARI" ADD CONSTRAINT "VANZARI_MEDICAMENT_FK1" FOREIGN KEY ("ID_MEDICAMENT")
	  REFERENCES "HR"."MEDICAMENT" ("ID_MEDICAMENT") ENABLE;
--------------------------------------------------------
--  DDL for Trigger ARHIVA_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."ARHIVA_TRIGGER_ID" 
before insert on ARHIVA
for each row
begin
select ARHIVA_SEQUENCE.nextval into :new.ID_ARHIVA from dual;
end;
/
ALTER TRIGGER "HR"."ARHIVA_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger CHITANTA_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."CHITANTA_TRIGGER_ID" 
before insert on CHITANTA
for each row
begin
select CHITANTA_SEQUENCE.nextval into :new.ID_CHITANTA from dual;
end;
/
ALTER TRIGGER "HR"."CHITANTA_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger DETALII_CHITANTA_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."DETALII_CHITANTA_TRIGGER_ID" 
before insert on DETALII_CHITANTA
for each row
begin
select DETALII_CHITANTA_SEQUENCE.nextval into :new.ID_DETALIICHITANTA from dual;
end;
/
ALTER TRIGGER "HR"."DETALII_CHITANTA_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger DETALII_RETETA_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."DETALII_RETETA_TRIGGER_ID" 
before insert on DETALII_RETETA
for each row
begin
select DETALII_RETETA_SEQUENCE.nextval into :new.ID_DETALIIRETETA from dual;
end;
/
ALTER TRIGGER "HR"."DETALII_RETETA_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger MEDICAMENT_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."MEDICAMENT_TRIGGER_ID" 
before insert on MEDICAMENT
for each row
begin
select MEDICAMENT_SEQUENCE.nextval into :new.ID_MEDICAMENT from dual;
end;
/
ALTER TRIGGER "HR"."MEDICAMENT_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger PRODUCATORI_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."PRODUCATORI_TRIGGER_ID" 
before insert on PRODUCATORI
for each row
begin
select PRODUCATORI_SEQUENCE.nextval into :new.ID_PRODUCATOR from dual;
end;
/
ALTER TRIGGER "HR"."PRODUCATORI_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger RETETA_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."RETETA_TRIGGER_ID" 
before insert on RETETA
for each row
begin
select RETETA_SEQUENCE.nextval into :new.ID_RETETA from dual;
end;
/
ALTER TRIGGER "HR"."RETETA_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger STOCURI_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."STOCURI_TRIGGER_ID" 
before insert on STOCURI
for each row
begin
select STOCURI_SEQUENCE.nextval into :new.ID_STOCURI from dual;
end;
/
ALTER TRIGGER "HR"."STOCURI_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger SUBSTANTA_ACTIVA_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."SUBSTANTA_ACTIVA_TRIGGER_ID" 
before insert on SUBSTANTA_ACTIVA
for each row
begin
select SUBSTANTA_ACTIVA_SEQUENCE.nextval into :new.ID_SUBSTANTA_ACTIVA from dual;
end;
/
ALTER TRIGGER "HR"."SUBSTANTA_ACTIVA_TRIGGER_ID" ENABLE;
--------------------------------------------------------
--  DDL for Trigger TRIGGER_VANZARI_AFTER_INSERT
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."TRIGGER_VANZARI_AFTER_INSERT" 
AFTER INSERT ON VANZARI 
FOR EACH ROW 
BEGIN
    MERGE INTO ARHIVA ar
    USING ( SELECT :new.ID_MEDICAMENT AS ID_MEDICAMENT, :new.CANTITATE AS CANTITATE FROM DUAL ) vanzare
    ON (ar.ID_MEDICAMENT = vanzare.ID_MEDICAMENT AND TRUNC(ar.DATA) = TRUNC(SYSDATE))
    WHEN MATCHED THEN
      UPDATE SET ar.CANTITATE = ar.CANTITATE + vanzare.CANTITATE
    WHEN NOT MATCHED THEN 
      INSERT (ar.ID_MEDICAMENT, ar.DATA, ar.CANTITATE)
      VALUES (vanzare.ID_MEDICAMENT, SYSDATE, vanzare.CANTITATE);
END;
/
ALTER TRIGGER "HR"."TRIGGER_VANZARI_AFTER_INSERT" ENABLE;
--------------------------------------------------------
--  DDL for Trigger VANZARI_TRIGGER_ID
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "HR"."VANZARI_TRIGGER_ID" 
before insert on VANZARI
for each row
begin
select VANZARI_SEQUENCE.nextval into :new.ID_VANZARE from dual;
end;
/
ALTER TRIGGER "HR"."VANZARI_TRIGGER_ID" ENABLE;
